package com.nantai.jiafang.nantaijiafang.activity.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nantai.jiafang.nantaijiafang.R;
import com.nantai.jiafang.nantaijiafang.bean.UnReadInfo;

import java.util.List;

/**
 * Created by wuning on 2016/8/9.
 */
public class UnReadListAdapter extends BaseAdapter {
    private String flag = "1";
    private List<UnReadInfo> list;
    private Context mContext;

    public UnReadListAdapter(Context context, List<UnReadInfo> data,String sign) {
        mContext = context;
        list = data;
        flag = sign;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_unreadcount, null);
            viewHolder = new ViewHolder();
            viewHolder.date = (TextView) convertView.findViewById(R.id.tv_date);
            viewHolder.count = (TextView) convertView.findViewById(R.id.tv_unread_count);
            viewHolder.bg = (LinearLayout)convertView.findViewById(R.id.bg);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.date.setText(list.get(position).getDate());
        if (list.get(position).getIsRead().equals("0")){
            viewHolder.count.setText(list.get(position).getCount());
        }else{
            viewHolder.count.setText("");
        }

        if (flag.equals("1")){
            viewHolder.bg.setBackgroundResource(R.mipmap.bg_push_item1);
        }else{
            viewHolder.bg.setBackgroundResource(R.mipmap.bg_push_item2);
        }
        return convertView;
    }

    class ViewHolder {
        TextView date,count;
        LinearLayout bg;
    }
}
